import java.io.FileWriter;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;

import au.com.bytecode.opencsv.CSVWriter;

/**
 * 
 */

/**
 * @author Paola
 *
 *This class print the information computed in the execution 
 *in the output files: 
 *3 files that contain the information of all the computations performed (altLabel, prefLabel, definition) 
 *1 file that contains the information specific of a thesaurus
 *
 *
 */

public class PrintToFileStatistics {
	
	
    public static void printThesaurusMultilingualResults(InfoJobThesaurusME job,  ConceptsForLanguage pl, ConceptsForLanguage al, 
			  ConceptsForLanguage def, HashMap<String,String> rt )throws Exception
			  {
    	  //stampa dati di un thesauro nel file del thesauro
    	//creo nome file thesauro

	    StringBuilder nameaux= new StringBuilder();
	    nameaux.append(job.getPathfileres());
	    nameaux.append(job.getNameResource().split("\\.")[0]);
	    nameaux.append("_");
	    nameaux.append(job.getVersion());
	    nameaux.append(".csv");
	    
	    
	    
	    
	    
	    String[] line1=new String[1];
	    String[] line2=new String[1];
	    String[] line3=new String[1];
	    String[] line4=new String[1];
	    String[] line5=new String[1];
	    String[] line6=new String[1];
	    String[] line7=new String[1];
	    
	    String[] labeline;
	    ArrayList<String[]> allines= new ArrayList<String[]>();
	    
	    
	    //file csv
	    FileWriter outFile = new FileWriter(nameaux.toString().trim(), Boolean.TRUE);
	    CSVWriter csvf= new CSVWriter(outFile);
	    
	
	    line1[0]=job.getNameResource();
	    line2[0]=job.getPathdumpResource();
	    line3[0]=job.getFormatResource();
	    line4[0]=job.getVersion();
	    line5[0]=job.getURIspaceResource();
	    line6[0]=job.getURLResource();
	    line7[0]=rt.get("totalnumberconcepts");
	    
	    
	    allines.add(line1);
	    allines.add(line2);
	    allines.add(line3);
	    allines.add(line4);
	    allines.add(line5);
	    allines.add(line6);
	    allines.add(line7);
	    labeline = new String[] {"prefLable"};
	    allines.add(labeline);
	    allines.add(pl.keyToStringArray());
	    allines.add(pl.valueToStringArray());
	    
	    
	    labeline = new String[] {"altLable"};
	    allines.add(labeline);
	    allines.add(al.keyToStringArray());
	    allines.add(al.valueToStringArray());
	    
	    
	    labeline = new String[] {"definition"};
	    allines.add(labeline);
	    allines.add(def.keyToStringArray());
	    allines.add(def.valueToStringArray());
	    
	    for(String[] l: allines)
	    {
		    csvf.writeNext(l);
	    }
	 
	    csvf.close();
	    outFile.close();
        

	    }
    
    
    public static void printTotalMultilingualResults(InfoJobThesaurusME job,  ConceptsForLanguage pl, ConceptsForLanguage al, 
			  ConceptsForLanguage def, HashMap<String,String> rt, CSVWriter csvfpl,CSVWriter csvfal,CSVWriter csvfdef  )throws Exception
			  {

	    
	    
	    //stampo i dati thesauro su file csv
	    
	    
	    String[] line1=new String[1];
	    String[] line2=new String[1];
	    String[] line3=new String[1];
	    String[] line4=new String[1];
	    String[] line5=new String[1];
	    String[] line6=new String[1];
	    String[] line7=new String[1];
	    
	    String[] labeline;
	    ArrayList<String[]> allines= new ArrayList<String[]>();
	    
	    
	    //strutture per percentuali totali 
	    Double conct;
	    PercentageForLanguage pltot;
	    PercentageForLanguage altot;
	    PercentageForLanguage deftot;
	  
	    

	    

	    //calcolo percentuali totali 
	    conct=Double.valueOf(rt.get("totalnumberconcepts"));
	    pltot=new PercentageForLanguage(pl,conct);
	    altot=new PercentageForLanguage(al,conct);
	    deftot=new PercentageForLanguage(def,conct);
	    
	    
	    
	    
	    //stampa nome thesauro 
	    
	    labeline = new String[] {job.getNameResource().split("\\.")[0]};

	  //percentuali prefLabel totali
	    allines.clear();
	    allines.add(labeline);
	    allines.add(pltot.valueToStringArray());
	    
	    for(String[] l: allines)
	    {
	    	csvfpl.writeNext(l);
	    }
	    
		  //percentuali altLabel totali	    
	    allines.clear();
	    allines.add(labeline);
	    allines.add(altot.valueToStringArray());

	    for(String[] l: allines)
	    {
	    	csvfal.writeNext(l);
	    }


	    //percentuali definition totali	    
	    allines.clear();    
	    allines.add(labeline);
	    allines.add(deftot.valueToStringArray());
	    
	    for(String[] l: allines)
	    {
	    	csvfdef.writeNext(l);
	    }
	 
	   
      

	    }    	
      

     
    
    
    
        
}



